﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_Chronicles_of_Asku.Areas.Tomb_Floors._10_20._15_20.Resources;
using The_Chronicles_of_Asku.Characters;

namespace The_Chronicles_of_Asku.Areas.Tomb_Floors._10_20._15_20
{
    class FloorSixteen
    {
        Battle battle = new Battle();
        Skeleton skel = new Skeleton();
        Necromancer necro = new Necromancer();
        Undead zombie = new Undead();
        SetMobLevels setLevel = new SetMobLevels();
        Hero myHero = new Hero();
        Villager villager = new Villager();
        public bool complete = false;

        public void theFloor(Hero myHero, Mob mob)
        {
            setLevel.setMobLevelTwentyOne(skel, necro, zombie, villager);

            Console.WriteLine(FloorSixteenText.Entrance);
            UndeadFight(myHero, zombie); //Seven Undead
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorSixteenText.SecondThing);
                SkeletonFight(myHero, skel);  //10 Skeleton
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
            }
            
            if (myHero.isAlive == true)
            {
                string answer = "";
                bool hasKey = false;

                do
                {
                    Console.WriteLine(FloorSixteenText.ThirdThing);
                    answer = Console.ReadLine();

                    switch (answer)
                    {
                        case "1":
                            if (myHero.isAlive == true)
                            {
                                Console.WriteLine(FloorSixteenText.ThirdThingOne);
                                SkeletonFight(myHero, skel);
                                UndeadFight(myHero, zombie);
                                SkeletonFight(myHero, skel);
                                UndeadFight(myHero, zombie);
                                UndeadFight(myHero, zombie);
                                SkeletonFight(myHero, skel);
                                if (myHero.isAlive == true)
                                {
                                    Random rnd = new Random();
                                    int goldInChest = rnd.Next(100, 501);
                                    myHero.gold += goldInChest;
                                    if (myHero.gold >= myHero.goldCap)
                                    {
                                        myHero.gold = myHero.goldCap;
                                    }
                                    int tempGold = myHero.gold; //Possible work around for bug not displaying how much gold the player had, instead just displaying the goldInChest twice
                                    Console.WriteLine(FloorSixteenText.ThirdThingOneTwo, goldInChest, tempGold); //tempGold used to be myHero.gold
                                    ClearScreen();
                                }
                            }
                            break;

                        case "2":
                            if (myHero.isAlive == true)
                            {
                                if (hasKey != true)
                                {
                                    Console.WriteLine(FloorSixteenText.ThirdThingTwo);
                                    ClearScreen();
                                    hasKey = false;
                                    answer = "0";
                                }
                            }
                            break;

                        case "3":
                            if (myHero.isAlive == true)
                            {
                                Console.WriteLine(FloorSixteenText.ThirdThingThree);
                                NecromancerFight(myHero, necro);
                                NecromancerFight(myHero, necro);
                                NecromancerFight(myHero, necro);
                                if (myHero.isAlive == true)
                                {
                                    hasKey = true;
                                }
                            }
                            break;

                        default:
                            Console.WriteLine("Invalid choice!");
                            ClearScreen();
                            break;
                    }
                } while (answer != "2" && hasKey == false && myHero.isAlive == true);
            }

            setLevel.setMobLevelTwentyTwo(skel, necro, zombie, villager);

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorSixteenText.FourthThing);
                SkeletonFight(myHero, skel);
                NecromancerFight(myHero, necro);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                NecromancerFight(myHero, necro);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                VillagerFight(myHero, villager);
                NecromancerFight(myHero, necro);
                UndeadFight(myHero, zombie);
                VillagerFight(myHero, villager);
                SkeletonFight(myHero, skel);
                UndeadFight(myHero, zombie);
                NecromancerFight(myHero, necro);
                VillagerFight(myHero, villager);
                SkeletonFight(myHero, skel);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);
                UndeadFight(myHero, zombie);
                SkeletonFight(myHero, skel);

            }

            if (myHero.isAlive == true)
            {
                string answer = "";

                do
                {
                    Console.WriteLine(FloorSixteenText.FifthThing);
                    answer = Console.ReadLine();

                    switch (answer)
                    {
                        case "1":
                            Console.WriteLine(FloorSixteenText.FifthThingLeft);
                            VillagerFight(myHero, villager);
                            VillagerFight(myHero, villager);
                            VillagerFight(myHero, villager);
                            VillagerFight(myHero, villager);
                            VillagerFight(myHero, villager);
                            VillagerFight(myHero, villager);
                            VillagerFight(myHero, villager);
                            break;

                        case "2":
                            Console.WriteLine(FloorSixteenText.FifthThingRight);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            break;

                        default:
                            Console.WriteLine("Invalid choice!");
                            ClearScreen();
                            break;
                    }
                } while (answer != "1" && answer != "2" && myHero.isAlive == true);
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine();
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorSixteenText.End);
                ClearScreen();
                complete = true;
            }


            if (myHero.isAlive == false)
            {
                Console.WriteLine(FloorSixteenText.Dead);
                myHero.isAlive = true;
            }
        }

        private void UndeadFight(Hero myHero, Undead zombie)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, zombie);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            zombie.ResetStats(zombie);

            Console.Clear();
        }

        private void SkeletonFight(Hero myHero, Skeleton skel)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, skel);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            skel.ResetStats(skel);

            Console.Clear();
        }

        private void NecromancerFight(Hero myHero, Necromancer necro)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, necro);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            necro.ResetStats(necro);

            Console.Clear();
        }

        private void VillagerFight(Hero myHero, Villager villager)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, villager);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            villager.ResetStats(villager);

            Console.Clear();
        }

        private void ClearScreen()
        {
            Console.ReadKey();
            Console.Clear();
        }
    }
}
